package com.sgcc.pda.sdk.dao.impl;

import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.text.TextUtils;

import com.sgcc.pda.baselibrary.exception.ExceptionInfo;
import com.sgcc.pda.baselibrary.utils.JsonUtil;
import com.sgcc.pda.baselibrary.utils.LogUtil;
import com.sgcc.pda.greendao.entity.AppBaseInfo;
import com.sgcc.pda.sdk.dao.ContentProviderDao;
import com.sgcc.pda.sdk.entity.BehaviorTrajectoryInfo;
import com.sgcc.pda.sdk.entity.DataBean;
import com.sgcc.pda.sdk.entity.MsgOfflineInfo;
import com.sgcc.pda.sdk.entity.TaskUpInfo;
import com.sgcc.pda.sdk.entity.TrafficStatsInfo;
import com.sgcc.pda.sdk.entity.table.AppApkInfo;
import com.sgcc.pda.sdk.entity.table.BaseTaskInfo;
import com.sgcc.pda.sdk.entity.table.FileInfo;
import com.sgcc.pda.sdk.entity.table.RegisterInfo;
import com.sgcc.pda.sdk.entity.table.SharepreferenceInfo;
import com.sgcc.pda.sdk.entity.table.UserInfo;
import com.sgcc.pda.sdk.utils.DataConversionUtil;
import com.sgcc.pda.sdk.utils.DataConvert;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 内容管理者数据库实现类.
 *
 * @author 王沛栋
 * @data 2018/1/19 14:18
 */

public class ContentProviderDaoImpl implements ContentProviderDao {
    private static final String CONTENT_PROVIDER_CONNECT =
            "content://com.sgcc.pda.safework.common.sharepreference.connect/";

    private static final String TABLE_SHAREPREFERENCE_INFO = "SHAREPREFERENCE_INFO";
    private static final String TABLE_EXCEPTION_INFO = "EXCEPTION_INFO";
    private static final String APP_WARNING_INFO = "APP_WARNING_INFO";//app警告信息
    private static final String TABLE_APP_INFO = "APP_INFO";
    private static final String TABLE_APP_DESKTOP_INFO = "APP_DESKTOP_INFO";
    private static final String TABLE_REGISTER_INFO = "REGISTER_INFO";
    private static final String TABLE_APP_BASE_INFO = "APP_BASE_INFO";
    private static final String TABLE_APP_TYPE = "TABLE_APP_TYPE";
    private static final String TABLE_FILE_INFO = "FILE_INFO";
    private static final String TABLE_USER_INFO = "USER_INFO";
    private static final String TABLE_MARKET_DESKTOP = "MARKET_DESKTOP";//市场桌面
    private static final String TABLE_TASK_CONSTANT_INFO = "TASK_CONSTANT_INFO";//工单常量
    private static final String BEHAVIOR_TRAJECTORY_INFO = "BEHAVIOR_TRAJECTORY_INFO";//用户行为轨迹
    private static final String FIND_REGISTER_INFO = "FIND_REGISTER_INFO";//查找注册信息
    private static final String UPDATE_APP_BASE_INFO_APK_STATE = "UPDATE_APP_BASE_INFO_APK_STATE";//更新apk状态
    private static final String SAVE_OR_UPDATE_APP_APK_STATE = "SAVE_OR_UPDATE_APP_APK_STATE";//保存下载状态
    private static final String FIND_APP_APK_INFO = "FIND_APP_APK_INFO";//查找APP APK

    //末端融合新增
    private static final String BASE_TASK_INFO = "BASE_TASK_INFO";//基础工单表
    private static final String APP_INSTALL_INFO = "APP_INSTALL_INFO";//应用安装信息表

    private static final String APP_BASE_INFO_BY_PACKAGENAME = "APP_BASE_INFO_BY_PACKAGENAME";//通过应用包名获取应用详情
    private static final String UPDATE_APP_BASE_INFO_APK_APPUPDATA = "UPDATE_APP_BASE_INFO_APK_APPUPDATA";//更新增量更新状态
    private static final String APP_BASE_INFO_BY_ADDUPDATA = "APP_BASE_INFO_BY_ADDUPDATA";//获取所有需要合并补丁包应用
    private static final String TABLE_DELETE_DESKTOP_INFO = "TABLE_DELETE_DESKTOP_INFO";//删除数据库中的桌面数据
    private static final String TABLE_APP_TRAFFICSTATS = "TABLE_APP_TRAFFICSTATS";//保存流量信息
    private static final String TABLE_APP_TASK_UP_INFO = "TABLE_APP_TASK_UP_INFO";//获取待上传工单信息
    private static final String TABLE_APP_MSG_OFFLINE_INFO = "TABLE_APP_MSG_OFFLINE_INFO";//保存离线消息信息
    private static final String TABLE_APP_TRAFFICSTATS_ALL = "0";//获取所有信息
    private static final String TABLE_APP_TRAFFICSTATS_MONTH = "1";//获取当月的流量信息
    private static final String TABLE_APP_TRAFFICSTATS_DAY = "2";//获取当天的流量信息

    /**
     * sp类型——boolean类型false
     */
    public static final String SP_TYPE_BOOLEAN_FALSE = "0";

    /**
     * sp类型——boolean类型true
     */
    public static final String SP_TYPE_BOOLEAN_TRUE = "1";


    /**
     * 存储类型boolean
     */
    private static final Map<String, Boolean> SP_TYPE_BOOLEAN = new HashMap<>();

    static {
        SP_TYPE_BOOLEAN.put(SP_TYPE_BOOLEAN_FALSE, false);
        SP_TYPE_BOOLEAN.put(SP_TYPE_BOOLEAN_TRUE, true);
    }

    /**
     * 定义log打印TAG
     */
    private String logTag = "ContentProviderDaoImpl";
    private String logContent = "logContent";
    private String saveData = "保存文件数据";
    private String intentId = "INTENT_ID";

    @Override
    public void setSharepreference(Context context, SharepreferenceInfo info) {
        ContentResolver resolver = context.getContentResolver();
        //定义要访问的ContentProvider的
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + TABLE_SHAREPREFERENCE_INFO);
        //通过反射  将实体类转成ContentValues
        ContentValues values = DataConversionUtil.BeanToContentValues(info);
        try {
            resolver.insert(uri, values);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 获取data应用定义的sp数据——String类型
     *
     * @param context
     * @param key
     * @return
     */
    @Override
    public String getSharepreferenceValue(Context context, String editKey, String key) {
        String result = null;
        ContentResolver resolver = context.getContentResolver();
        //定义要访问的ContentProvider的
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + TABLE_SHAREPREFERENCE_INFO);

        Cursor cursor = null;

//if (cursor != null){
//
//}
        try {
            //获取表中所有记录
            cursor = resolver.query(uri, null, null, new String[]{key, editKey}, null);
        } catch (Exception e) {
            LogUtil.d(logTag, logContent + e.getMessage());
            return null;
        }

        if (null == cursor) {
            return null;
        }


        while (cursor.moveToNext()) {
            result = cursor.getString(0);

        }
        cursor.close();
        cursor = null;
        return result;
    }


    /**
     * 获取data应用定义的sp数据——boolean类型
     *
     * @param context
     * @param key
     * @return
     */
    @Override
    public boolean getSharepreferenceBooleanValue(Context context, String editKey, String key) {
        String result = null;
        ContentResolver resolver = context.getContentResolver();
        //定义要访问的ContentProvider的
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + TABLE_SHAREPREFERENCE_INFO);

        Cursor cursor = null;
        try {
            //获取表中所有记录
            cursor = resolver.query(uri, null, null, new String[]{key, editKey}, null);
        } catch (Exception e) {
            LogUtil.e(logTag, logContent + e.getMessage());
            return false;
        }
        if (null == cursor) {
            return false;
        }

        while (cursor.moveToNext()) {
            result = cursor.getString(0);

        }
        cursor.close();

        if (TextUtils.isEmpty(result)) {
            return false;
        }

        return SP_TYPE_BOOLEAN.get(result);

    }

    @Override
    public boolean deletAppBaseInfoByAppNo(Context context, String appNo) {
        ContentResolver resolver = context.getContentResolver();
        //定义要访问的ContentProvider的
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + BASE_TASK_INFO);
        int result = resolver.delete(uri, null, new String[]{appNo});
        if (result == 1) {
            return true;
        } else {
            return false;
        }

    }

    @Override
    public void saveExceptionInfo(Context context, ExceptionInfo obj) {
        ContentResolver resolver = context.getContentResolver();
        //定义要访问的ContentProvider的
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + TABLE_EXCEPTION_INFO);
        //通过反射  将实体类转成ContentValues
        ContentValues values = DataConversionUtil.BeanToContentValues(obj);
        resolver.insert(uri, values);
    }

    @Override
    public List<ExceptionInfo> getExceptionInfoList(Context context) {
        ContentResolver resolver = context.getContentResolver();
        //定义要访问的ContentProvider的
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + TABLE_EXCEPTION_INFO);

        Cursor cursor = null;
        try {
            //获取表中所有记录
            cursor = resolver.query(uri, null, null, null, null);
        } catch (Exception e) {
            LogUtil.e(logTag, logContent + e.getMessage());
            return null;
        }
        if (null == cursor) {
            return null;
        }
        List<ExceptionInfo> list = DataConvert.cursor2VOList(cursor, ExceptionInfo.class);
        cursor.close();
        return list;

    }


    @Override
    public void saveAppBaseInfo(Context context, AppBaseInfo info) {

        ContentResolver resolver = context.getContentResolver();
        //定义要访问的ContentProvider的
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + TABLE_APP_BASE_INFO);
        //通过反射  将实体类转成ContentValues
        ContentValues values = DataConversionUtil.BeanToContentValues(info);

        if (null == values) {
        } else {
            resolver.insert(uri, values);
        }

    }

    @Override
    public List<AppBaseInfo> getAppTypeList(Context context) {
        ContentResolver resolver = context.getContentResolver();
        //定义要访问的ContentProvider的
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + TABLE_APP_TYPE);
        List<AppBaseInfo> list = new ArrayList<>();
        Cursor cursor = null;
        try {
            //获取表中所有记录
            cursor = resolver.query(uri, null, null, null, null);
        } catch (Exception e) {
            LogUtil.e(logTag, logContent + e.getMessage());
            return list;
        }
        if (null == cursor) {
            return list;
        }

        while (cursor.moveToNext()) {
            AppBaseInfo info = new AppBaseInfo();
            info.setVerSortImg(cursor.getString(cursor.getColumnIndex(AppBaseInfo.VER_SORT_IMG)));
            info.setVerSortId(cursor.getString(cursor.getColumnIndex(AppBaseInfo.VER_SORT_ID)));
            info.setVerSortName(cursor.getString(cursor.getColumnIndex(AppBaseInfo.VER_SORT_NAME)));
            info.setAppInstallMethod(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_INSTALL_METHOD)));
            list.add(info);
        }
        cursor.close();

        return list;
    }

    @Override
    public List<AppBaseInfo> getAppBaseInfoList(Context context) {
        ContentResolver resolver = context.getContentResolver();
        //定义要访问的ContentProvider的
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + TABLE_APP_BASE_INFO);

        Cursor cursor = null;
        try {
            //获取表中所有记录
            cursor = resolver.query(uri, null, null, null, null);
        } catch (Exception e) {
            LogUtil.e(logTag, logContent + e.getMessage());
            return null;
        }
        if (null == cursor) {
            return null;
        }
        List<AppBaseInfo> list = new ArrayList<>();
        while (cursor.moveToNext()) {
            AppBaseInfo info = new AppBaseInfo();

            info.setAppIcon(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_ICON)));
            info.setAppName(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_NAME)));
            info.setAppPackage(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_PACKAGE)));
            info.setAppFilePath(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_FILE_PATH)));
            info.setAppId(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_ID)));
            info.setVerSortId(cursor.getString(cursor.getColumnIndex(AppBaseInfo.VER_SORT_ID)));
            info.setVerSortName(cursor.getString(cursor.getColumnIndex(AppBaseInfo.VER_SORT_NAME)));
            info.setVerTypeCode(cursor.getInt(cursor.getColumnIndex(AppBaseInfo.VER_TYPE_CODE)));
            info.setVerTypeName(cursor.getString(cursor.getColumnIndex(AppBaseInfo.VER_TYPE_NAME)));
            info.setAppUnitId(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_UNIT_ID)));
            info.setAppUnitName(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_UNIT_NAME)));
            info.setPubRemark(cursor.getString(cursor.getColumnIndex(AppBaseInfo.PUB_REMARK)));
            info.setHardwareVer(cursor.getString(cursor.getColumnIndex(AppBaseInfo.HARDWARE_VER)));
            info.setPubType(cursor.getString(cursor.getColumnIndex(AppBaseInfo.PUB_TYPE)));
            info.setVerSortImg(cursor.getString(cursor.getColumnIndex(AppBaseInfo.VER_SORT_IMG)));
            info.setPubTime(cursor.getString(cursor.getColumnIndex(AppBaseInfo.PUB_TIME)));
            info.setApkFileSize(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APK_FILE_SIZE)));
            info.setAppPubStatus(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_PUB_STATUS)));
            info.setAppBugFilePath(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_BUG_FILE_PATH)));
            info.setApkBugFileSize(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APK_BUG_FILE_SIZE)));
            info.setIsAuthor(cursor.getString(cursor.getColumnIndex(AppBaseInfo.IS_AUTHOR)));
            info.setAppInstallMethod(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_INSTALL_METHOD)));
            info.setAppUpdateState(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_UPDATE_STATE)));
            info.setDeskName(cursor.getString(cursor.getColumnIndex(AppBaseInfo.DESK_NAME)));
            info.setRelPageName(cursor.getString(cursor.getColumnIndex(AppBaseInfo.RELPAGENAME)));
            info.setAppFileMD5(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APPFILEMD5)));
            info.setAppBugFilePath(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APPBUGFILEPATH)));
            info.setAppBugFileMD5(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APPBUGFILEMD5)));
            info.setAppStartActivity(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_START_ACTIVITY)));
            list.add(info);
        }
        cursor.close();

        return list;

    }


    @Override
    public List<AppBaseInfo> getAppBaseInfoListBySearchAppName(Context context, String name) {
        ContentResolver resolver = context.getContentResolver();
        //定义要访问的ContentProvider的
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + TABLE_APP_BASE_INFO);

        Cursor cursor = null;
        try {
            //获取表中所有记录
            cursor = resolver.query(uri, null, null, new String[]{name}, null);
        } catch (Exception e) {
            LogUtil.e(logTag, logContent + e.getMessage());
            return null;
        }
        if (null == cursor) {
            return null;
        }
        List<AppBaseInfo> list = new ArrayList<>();

        try {
            while (cursor.moveToNext()) {
                AppBaseInfo info = new AppBaseInfo();

                info.setAppIcon(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_ICON)));
                info.setAppName(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_NAME)));
                info.setAppPackage(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_PACKAGE)));
                info.setAppFilePath(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_FILE_PATH)));
                info.setAppId(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_ID)));
                info.setVerSortId(cursor.getString(cursor.getColumnIndex(AppBaseInfo.VER_SORT_ID)));
                info.setVerSortName(cursor.getString(cursor.getColumnIndex(AppBaseInfo.VER_SORT_NAME)));
                info.setVerTypeCode(cursor.getInt(cursor.getColumnIndex(AppBaseInfo.VER_TYPE_CODE)));
                info.setVerTypeName(cursor.getString(cursor.getColumnIndex(AppBaseInfo.VER_TYPE_NAME)));
                info.setAppUnitId(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_UNIT_ID)));
                info.setAppUnitName(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_UNIT_NAME)));
                info.setPubRemark(cursor.getString(cursor.getColumnIndex(AppBaseInfo.PUB_REMARK)));
                info.setHardwareVer(cursor.getString(cursor.getColumnIndex(AppBaseInfo.HARDWARE_VER)));
                info.setPubType(cursor.getString(cursor.getColumnIndex(AppBaseInfo.PUB_TYPE)));
                info.setVerSortImg(cursor.getString(cursor.getColumnIndex(AppBaseInfo.VER_SORT_IMG)));
                info.setPubTime(cursor.getString(cursor.getColumnIndex(AppBaseInfo.PUB_TIME)));
                info.setApkFileSize(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APK_FILE_SIZE)));
                info.setAppPubStatus(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_PUB_STATUS)));
                info.setUpdType(cursor.getString(cursor.getColumnIndex(AppBaseInfo.UPD_TYPE)));
                info.setVerCode(cursor.getString(cursor.getColumnIndex(AppBaseInfo.VER_CODE)));
                info.setAppBugFilePath(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_BUG_FILE_PATH)));
                info.setApkBugFileSize(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APK_BUG_FILE_SIZE)));
                info.setAppUpdateState(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_UPDATE_STATE)));
                info.setAppPubId(cursor.getString(cursor.getColumnIndex("appPubId")));
                info.setAppFileMD5(cursor.getString(cursor.getColumnIndex("appFileMD5")));
                info.setAppBugFileMD5(cursor.getString(cursor.getColumnIndex("appBugFileMD5")));
                info.setIsAuthor(cursor.getString(cursor.getColumnIndex(AppBaseInfo.IS_AUTHOR)));
                info.setAppInstallMethod(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_INSTALL_METHOD)));
                info.setDeskName(cursor.getString(cursor.getColumnIndex(AppBaseInfo.DESK_NAME)));
                info.setRelName(cursor.getString(cursor.getColumnIndex("relName")));
                info.setRelPageName(cursor.getString(cursor.getColumnIndex("relPageName")));
                info.setAppScreenShot(cursor.getString(cursor.getColumnIndex("appScreenShot")));
                info.setAppStartActivity(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_START_ACTIVITY)));
                list.add(info);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        cursor.close();
        return list;

    }


    @Override
    public FileInfo getFileInfo(Context context, String fileNo) {
        ContentResolver resolver = context.getContentResolver();
        //定义要访问的ContentProvider的
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + TABLE_FILE_INFO);

        Cursor cursor = null;
        try {
            //获取表中所有记录
            cursor = resolver.query(uri, null, null, new String[]{fileNo}, null);
        } catch (Exception e) {
            LogUtil.e(logTag, logContent + e.getMessage());
            return null;
        }

        if (null == cursor) {
            return null;
        }

        FileInfo info = new FileInfo();
        while (cursor.moveToNext()) {
            info.setFIDNO(cursor.getString(cursor.getColumnIndex("FIDNO")));
            info.setFILELOCPATH(cursor.getString(cursor.getColumnIndex("FILELOCPATH")));
            info.setFILENAME(cursor.getString(cursor.getColumnIndex("FILENAME")));
        }
        cursor.close();
        return info;
    }

    @Override
    public void saveFileInfo(Context context, FileInfo info) {
        LogUtil.e(logTag, saveData);
        ContentResolver resolver = context.getContentResolver();
        //定义要访问的ContentProvider的
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + TABLE_FILE_INFO);
        //通过反射  将实体类转成ContentValues
        ContentValues values = DataConversionUtil.BeanToContentValues(info);
        resolver.insert(uri, values);
    }

    /**
     * 保存注册信息
     *
     * @param context
     * @param info
     */
    @Override
    public void saveRegisterInfo(Context context, RegisterInfo info) {
        LogUtil.e(logTag, saveData);
        ContentResolver resolver = context.getContentResolver();
        //定义要访问的ContentProvider的
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + TABLE_REGISTER_INFO);
        //通过反射  将实体类转成ContentValues
        ContentValues values = DataConversionUtil.BeanToContentValues(info);
        resolver.insert(uri, values);
    }

    @Override
    public boolean deleteRegisterInfo(Context context) {
        LogUtil.e(logTag, saveData);
        ContentResolver resolver = context.getContentResolver();
        //定义要访问的ContentProvider的
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + TABLE_REGISTER_INFO);
        int result = resolver.delete(uri, null, null);
        if (result == 1) {
            return true;
        } else {
            return false;
        }
    }


    @Override
    public RegisterInfo getRegisterInfo(Context context) {
        ContentResolver resolver = context.getContentResolver();
        //定义要访问的ContentProvider的
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + FIND_REGISTER_INFO);

        Cursor cursor = null;
        try {
            //获取表中所有记录
            cursor = resolver.query(uri, null, null, new String[]{}, null);
        } catch (Exception e) {
            LogUtil.e(logTag, logContent + e.getMessage());
            return null;
        }

        if (null == cursor) {
            return null;
        }

        RegisterInfo info = new RegisterInfo();
        while (cursor.moveToNext()) {
            info.setREG_IDX(cursor.getString(cursor.getColumnIndex("REG_IDX")));
            info.setOPT_CODE(cursor.getString(cursor.getColumnIndex("OPT_CODE")));
            info.setMAC(cursor.getString(cursor.getColumnIndex("MAC")));
            info.setCODE_CIPHER(cursor.getString(cursor.getColumnIndex("CODE_CIPHER")));
            info.setRandomM(cursor.getString(cursor.getColumnIndex("RandomM")));
        }
        cursor.close();
        return info;

    }

    /**
     * 保存掌机使用人列表
     *
     * @param context
     * @param str
     */
    @Override
    public void saveUserInfoList(Context context, String str) {
        ContentResolver resolver = context.getContentResolver();
        //定义要访问的ContentProvider的
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + TABLE_USER_INFO);
        //通过反射  将实体类转成ContentValues
        ContentValues values = new ContentValues();
        values.put(intentId, str);
        resolver.insert(uri, values);
    }

    @Override
    public List<UserInfo.User> getUserInfoList(Context context, String key) {
        ContentResolver resolver = context.getContentResolver();
        //定义要访问的ContentProvider的
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + TABLE_USER_INFO);
        Cursor cursor = null;
        try {
            //获取表中所有记录
            cursor = resolver.query(uri, null, null, new String[]{"%" + key + "%"},
                    null);
        } catch (Exception e) {
            LogUtil.e(logTag, logContent + e.getMessage());
            return null;
        }

        if (0 == cursor.getCount()) {
            return null;
        }
        List<UserInfo.User> list = null;
        while (cursor.moveToNext()) {
            if (list == null) {
                list = new ArrayList<>();
            }
            UserInfo.User user = new UserInfo.User();
            user.setUSER_PINYIN(cursor.getString(cursor.getColumnIndex("USER_PINYIN")));
            user.setUSER_CODE(cursor.getString(cursor.getColumnIndex("USER_CODE")));
            user.setUSER_NAME(cursor.getString(cursor.getColumnIndex("USER_NAME")));

            list.add(user);
        }
        cursor.close();
        return list;

    }

    @Override
    public boolean deleteUserInfoList(Context context) {
        ContentResolver resolver = context.getContentResolver();
        //定义要访问的ContentProvider的
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + TABLE_USER_INFO);
        int result = resolver.delete(uri, null, null);
        if (result == 1) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public void saveMarketDesktopInfo(Context context, List<AppBaseInfo> list) {
        JSONArray ja = new JSONArray();
        for (AppBaseInfo info : list) {
            JSONObject jb = new JSONObject();
            try {
                jb.put(AppBaseInfo.APP_PACKAGE, info.getAppPackage());
                jb.put(AppBaseInfo.APP_ICON, info.getAppIcon());
                jb.put(AppBaseInfo.APP_ID, info.getAppId());
                jb.put(AppBaseInfo.APP_NAME, info.getAppName());
                jb.put(AppBaseInfo.APP_FILE_PATH, info.getAppFilePath());
                jb.put(AppBaseInfo.UPD_TYPE, info.getUpdType());
                jb.put(AppBaseInfo.VER_CODE, info.getVerCode());
                jb.put(AppBaseInfo.VER_TYPE_CODE, info.getVerTypeCode());
                jb.put(AppBaseInfo.APP_START_ACTIVITY, info.getAppStartActivity());

                ja.put(jb);

            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        ContentResolver resolver = context.getContentResolver();
        //定义要访问的ContentProvider的
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + TABLE_MARKET_DESKTOP);
        ContentValues values = new ContentValues();
        values.put(intentId, ja.toString());
        resolver.insert(uri, values);
    }

    @Override
    public boolean deleteMarketDesktopInfo(Context context, String packageName) {
        ContentResolver resolver = context.getContentResolver();
        //定义要访问的ContentProvider的
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + TABLE_DELETE_DESKTOP_INFO);
        int result = resolver.delete(uri, null, new String[]{packageName});
        if (result == 1) {
            return true;
        } else {
            return false;
        }
    }


    @Override
    public List<AppApkInfo> selectAppBaseInfoByAddUpdate(Context context, String addUpdate) {
        ContentResolver resolver = context.getContentResolver();

        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + APP_BASE_INFO_BY_ADDUPDATA);
        Cursor cursor = null;

        try {
            cursor = resolver.query(uri, null, null, new String[]{addUpdate}, null);
        } catch (Exception e) {
            return null;
        }
        if (null == cursor) {
            return null;
        }

        List<AppApkInfo> list = new ArrayList<>();
        while (cursor.moveToNext()) {

            AppApkInfo appApkInfo = new AppApkInfo();
            appApkInfo.setAppPackage(cursor.getString(cursor.getColumnIndex(AppApkInfo.APP_PACKAGE)));
            appApkInfo.setAppName(cursor.getString(cursor.getColumnIndex(AppApkInfo.APP_NAME)));
            appApkInfo.setAddUpdate(cursor.getString(cursor.getColumnIndex(AppApkInfo.ADD_UPDATE)));


            list.add(appApkInfo);
        }
        cursor.close();
        return list;
    }

    @Override
    public List<AppBaseInfo> getMarketTopInfo(Context context) {
        ContentResolver resolver = context.getContentResolver();
        //定义要访问的ContentProvider的
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + TABLE_MARKET_DESKTOP);
        Cursor cursor = null;
        try {
            //获取表中所有记录
            cursor = resolver.query(uri, null, null, new String[]{""},
                    null);
        } catch (Exception e) {
            LogUtil.e(logTag, logContent + e.getMessage());
            return null;
        }

        if (null == cursor) {
            return null;
        }
        List<AppBaseInfo> list = null;
        while (cursor.moveToNext()) {
            if (list == null) {
                list = new ArrayList<>();
            }
            AppBaseInfo appBaseInfo = new AppBaseInfo();
            appBaseInfo.setAppId(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_ID)));
            appBaseInfo.setAppPackage(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_PACKAGE)));
            appBaseInfo.setAppIcon(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_ICON)));
            appBaseInfo.setAppName(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_NAME)));
            appBaseInfo.setAppFilePath(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_FILE_PATH)));
            appBaseInfo.setAppPubStatus(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_PUB_STATUS)));
            appBaseInfo.setAppUpdateState(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_UPDATE_STATE)));
            appBaseInfo.setVerTypeCode(cursor.getInt(cursor.getColumnIndex(AppBaseInfo.VER_TYPE_CODE)));
            appBaseInfo.setUpdType(cursor.getString(cursor.getColumnIndex(AppBaseInfo.UPD_TYPE)));
            appBaseInfo.setVerCode(cursor.getString(cursor.getColumnIndex(AppBaseInfo.VER_CODE)));
            appBaseInfo.setAppStartActivity(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_START_ACTIVITY)));


            list.add(appBaseInfo);
        }
        cursor.close();
        return list;
    }

    @Override
    public List<AppBaseInfo> getSortMarketTopInfo(Context context, String dId) {
        ContentResolver resolver = context.getContentResolver();
        //定义要访问的ContentProvider的
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + TABLE_MARKET_DESKTOP);
        Cursor cursor = null;
        try {
            //获取表中所有记录
            cursor = resolver.query(uri, null, null, new String[]{dId},
                    null);
        } catch (Exception e) {
            LogUtil.e(logTag, logContent + e.getMessage());
            return null;
        }

        if (null == cursor) {
            return null;
        }
        List<AppBaseInfo> list = null;
        while (cursor.moveToNext()) {
            if (list == null) {
                list = new ArrayList<>();
            }
            AppBaseInfo appBaseInfo = new AppBaseInfo();
            appBaseInfo.setAppId(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_ID)));
            appBaseInfo.setAppPackage(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_PACKAGE)));
            appBaseInfo.setAppIcon(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_ICON)));
            appBaseInfo.setAppName(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_NAME)));
            appBaseInfo.setAppFilePath(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_FILE_PATH)));
            appBaseInfo.setAppPubStatus(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_PUB_STATUS)));
            appBaseInfo.setAppUpdateState(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_UPDATE_STATE)));
            appBaseInfo.setVerTypeCode(cursor.getInt(cursor.getColumnIndex(AppBaseInfo.VER_TYPE_CODE)));
            appBaseInfo.setIsAuthor(cursor.getString(cursor.getColumnIndex(AppBaseInfo.IS_AUTHOR)));
            appBaseInfo.setUpdType(cursor.getString(cursor.getColumnIndex(AppBaseInfo.UPD_TYPE)));
            appBaseInfo.setVerCode(cursor.getString(cursor.getColumnIndex(AppBaseInfo.VER_CODE)));
            appBaseInfo.setAppInstallMethod(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_INSTALL_METHOD)));
            appBaseInfo.setAppStartActivity(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_START_ACTIVITY)));
            list.add(appBaseInfo);
        }
        cursor.close();
        return list;
    }

    @Override
    public boolean updateAppBaseInfoApkState(Context context, String packageName, int state) {
        ContentResolver resolver = context.getContentResolver();
        //定义要访问的ContentProvider的
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + UPDATE_APP_BASE_INFO_APK_STATE);
        ContentValues values = new ContentValues();
        values.put(intentId, "test");
        int result = resolver.update(uri, values, null, new String[]{packageName, state + ""});
        if (result == 1) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public boolean saveOrUpdateAppApkInfoState(Context context,
                                               String packageName, int state, String progress) {
        ContentResolver resolver = context.getContentResolver();
        //定义要访问的ContentProvider的
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + SAVE_OR_UPDATE_APP_APK_STATE);


        ContentValues values = new ContentValues();
        values.put(intentId, "test");
        int result = resolver.update(uri, values, null, new String[]{packageName, state + "", progress});
        if (result == 1) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public boolean saveOrUpdateAppApkInfoState(Context context,
                                               String packageName, int state, String progress, String appName) {
        ContentResolver resolver = context.getContentResolver();
        //定义要访问的ContentProvider的
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + SAVE_OR_UPDATE_APP_APK_STATE);


        ContentValues values = new ContentValues();
        values.put(intentId, "test");
        int result = resolver.update(uri, values, null, new String[]{packageName, state + "", progress, appName});
        if (result == 1) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public boolean saveAddOrUpdateAppBaseInfoState(Context context, String packageName, String addUpDate) {
        ContentResolver resolver = context.getContentResolver();
        //定义要访问的ContentProvider的
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + UPDATE_APP_BASE_INFO_APK_APPUPDATA);
        ContentValues values = new ContentValues();
        values.put(intentId, "test");
        try {
            int result = resolver.update(uri, values, null, new String[]{packageName, addUpDate});
            return result == 1;
        } catch (Exception e) {
            e.getLocalizedMessage();
        }
        return false;
    }

    @Override
    public AppApkInfo getAppApkInfoByPackageName(Context context, String packageName) {
        ContentResolver resolver = context.getContentResolver();
        //定义要访问的ContentProvider的
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + FIND_APP_APK_INFO);

        Cursor cursor = null;
        try {
            //获取表中所有记录
            cursor = resolver.query(uri, null, null, new String[]{packageName}, null);
        } catch (Exception e) {
            LogUtil.e(logTag, logContent + e.getMessage());
            return null;
        }

        if (null == cursor) {
            return null;
        }

        AppApkInfo info = new AppApkInfo();
        while (cursor.moveToNext()) {
            info.setApkFileState(cursor.getInt(cursor.getColumnIndex("apkFileState")));
            info.setAppPackage(cursor.getString(cursor.getColumnIndex(AppApkInfo.APP_PACKAGE)));
            info.setAppDownloadProgress(cursor.getString(cursor.getColumnIndex("appDownloadProgress")));
            info.setAppName(cursor.getString(cursor.getColumnIndex(AppApkInfo.APP_NAME)));
            info.setAddUpdate(cursor.getString(cursor.getColumnIndex(AppApkInfo.ADD_UPDATE)));
        }
        cursor.close();
        return info;
    }

    @Override
    public boolean deletAppBaseInfo(Context context) {
        LogUtil.e("保存应用信息");
        ContentResolver resolver = context.getContentResolver();
        //定义要访问的ContentProvider的
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + TABLE_APP_BASE_INFO);
        int result = resolver.delete(uri, null, null);
        if (result == 1) {
            return true;
        } else {
            return false;
        }

    }

    @Override
    public void saveOrUpdateBaseTaskInfo(Context context, List<BaseTaskInfo> list) {
        ContentResolver resolver = context.getContentResolver();
        //定义要访问的ContentProvider的
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + BASE_TASK_INFO);

        ContentValues values = new ContentValues();

        String jsonStr = JsonUtil.listToString(list, BaseTaskInfo.class);
        LogUtil.e("基础工单数据转换字符串:" + jsonStr);
        values.put(intentId, jsonStr);
        resolver.insert(uri, values);
    }

    @Override
    public List<BaseTaskInfo> getBaseTaskInfoList(Context context, String[] selectArgs) {
        ContentResolver resolver = context.getContentResolver();
        //定义要访问的ContentProvider的
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + BASE_TASK_INFO);

        Cursor cursor = null;
        try {
            //获取表中所有记录
            cursor = resolver.query(uri, null, null, selectArgs, null);
        } catch (Exception e) {
            LogUtil.e(logTag, logContent + e.getMessage());
        }


        List<BaseTaskInfo> list = new ArrayList<>();
        if (cursor != null) {
            while (cursor.moveToNext()) {
                BaseTaskInfo info = new BaseTaskInfo();
                info.setAppNo(cursor.getString(cursor.getColumnIndex("appNo")));
                info.setDevType(cursor.getString(cursor.getColumnIndex("devType")));
                info.setBusiName(cursor.getString(cursor.getColumnIndex("busiName")));
                info.setROWNUM(cursor.getString(cursor.getColumnIndex("ROWNUM")));
                info.setOperatorNo(cursor.getString(cursor.getColumnIndex("operatorNo")));
                info.setConsName(cursor.getString(cursor.getColumnIndex("consName")));
                info.setDevAssetNo(cursor.getString(cursor.getColumnIndex("devAssetNo")));
                info.setDevInsAdd(cursor.getString(cursor.getColumnIndex("devInsAdd")));
                info.setConsId(cursor.getString(cursor.getColumnIndex("consId")));
                info.setAppId(cursor.getString(cursor.getColumnIndex(BaseTaskInfo.APP_ID)));
                info.setTgId(cursor.getString(cursor.getColumnIndex("tgId")));
                info.setPriorityLvl(cursor.getString(cursor.getColumnIndex("priorityLvl")));
                info.setTgName(cursor.getString(cursor.getColumnIndex("tgName")));
                info.setVoltCode(cursor.getString(cursor.getColumnIndex("voltCode")));
                info.setTgNo(cursor.getString(cursor.getColumnIndex("tgNo")));
                info.setOrgName(cursor.getString(cursor.getColumnIndex("orgName")));
                info.setWarningDate(cursor.getString(cursor.getColumnIndex("warningDate")));
                info.setActivityNo(cursor.getString(cursor.getColumnIndex("activityNo")));
                info.setOverdureDate(cursor.getString(cursor.getColumnIndex("overdureDate")));
                info.setConsNo(cursor.getString(cursor.getColumnIndex("consNo")));
                info.setAppStatus(cursor.getString(cursor.getColumnIndex("appStatus")));
                info.setProTitle(cursor.getString(cursor.getColumnIndex("proTitle")));
                info.setTimeStamp(cursor.getString(cursor.getColumnIndex("timeStamp")));
                info.setBeginDate(cursor.getString(cursor.getColumnIndex("beginDate")));
                info.setWkstTypeCode(cursor.getString(cursor.getColumnIndex("wkstTypeCode")));
                info.setAppTypeCode(cursor.getString(cursor.getColumnIndex("appTypeCode")));
                info.setElecAddr(cursor.getString(cursor.getColumnIndex("elecAddr")));
                info.setAppSource(cursor.getString(cursor.getColumnIndex("appSource")));
                info.setPlanConsNo(cursor.getString(cursor.getColumnIndex("planConsNo")));
                //info.SETU(cursor.getString(cursor.getColumnIndex("USER_CODE")));
                info.setWarningDateLong(cursor.getLong(cursor.getColumnIndex("warningDateLong")));
                info.setOverdureDateLong(cursor.getLong(cursor.getColumnIndex("overdureDateLong")));
                // info.setOverdureDateLong(cursor.getLong(cursor.getColumnIndex("ORDER_STATE")));
                info.setGPSLONGITUDE(cursor.getString(cursor.getColumnIndex("GPSLONGITUDE")));
                info.setGPSLATITUDE(cursor.getString(cursor.getColumnIndex("GPSLATITUDE")));
                info.setLineName(cursor.getString(cursor.getColumnIndex("lineName")));
                info.setLineId(cursor.getString(cursor.getColumnIndex("lineId")));
                info.setLineNo(cursor.getString(cursor.getColumnIndex("lineNo")));
                info.setReciveDateLong(cursor.getLong(cursor.getColumnIndex("reciveDateLong")));
                info.setReciveDate(cursor.getString(cursor.getColumnIndex("reciveDate")));
                info.setBeginDateLong(cursor.getLong(cursor.getColumnIndex("beginDateLong")));
                String alternateFieldJson = cursor.getString(cursor.getColumnIndex("alternateField"));
                if (!TextUtils.isEmpty(alternateFieldJson)) {
                    BaseTaskInfo.AlternateFieldBean alternateFieldBean = JsonUtil.parseJsonToBean(alternateFieldJson, BaseTaskInfo.AlternateFieldBean.class);
                    info.setAlternateField(alternateFieldBean);
                }
                list.add(info);
            }
            cursor.close();
        }
        return list;
    }

    @Override
    public int getSonTaskNumInfo(Context context, String[] selectArgs) {
        ContentResolver resolver = context.getContentResolver();
        //定义要访问的ContentProvider的
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + BASE_TASK_INFO);
        Cursor cursor = null;
        try {
            //获取表中所有记录
            cursor = resolver.query(uri, null, null, selectArgs, null);
        } catch (Exception e) {
            LogUtil.e(logTag, logContent + e.getMessage());
            return 0;
        }
        if (null == cursor) {
            return 0;
        }
        int count = cursor.getCount();
        cursor.close();
        return count;
    }

    @Override
    public void saveOrUpdateAppInstallInfoList(Context context, List<AppBaseInfo> list, int state) {
        ContentResolver resolver = context.getContentResolver();
        //定义要访问的ContentProvider的
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + APP_INSTALL_INFO);

        ContentValues values = new ContentValues();
        String jsonStr = JsonUtil.listToString(list, AppBaseInfo.class);
        values.put(intentId, jsonStr);
        values.put("TYPE", state);
        resolver.insert(uri, values);
    }

    @Override
    public List<AppBaseInfo> getAppInstallInfoList(Context context) {
        ContentResolver resolver = context.getContentResolver();
        //定义要访问的ContentProvider的
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + APP_INSTALL_INFO);

        Cursor cursor = null;
        try {
            //获取表中所有记录
            cursor = resolver.query(uri, null, null, null, null);
            LogUtil.e(logTag, "获取cursor成功");
        } catch (Exception e) {
            LogUtil.e(logTag, logContent + e.getMessage());
            return null;
        }

        if (null == cursor) {
            return null;
        }

        List<AppBaseInfo> list = new ArrayList<>();
        while (cursor.moveToNext()) {
            AppBaseInfo info = new AppBaseInfo();

            info.setAppIcon(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_ICON)));
            info.setAppName(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_NAME)));
            info.setAppPackage(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_PACKAGE)));
            info.setAppFilePath(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_FILE_PATH)));
            info.setAppId(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_ID)));
            info.setVerSortId(cursor.getString(cursor.getColumnIndex(AppBaseInfo.VER_SORT_ID)));
            info.setVerSortName(cursor.getString(cursor.getColumnIndex(AppBaseInfo.VER_SORT_NAME)));
            info.setVerTypeCode(cursor.getInt(cursor.getColumnIndex(AppBaseInfo.VER_TYPE_CODE)));
            info.setVerTypeName(cursor.getString(cursor.getColumnIndex(AppBaseInfo.VER_TYPE_NAME)));
            info.setAppUnitId(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_UNIT_ID)));
            info.setAppUnitName(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_UNIT_NAME)));
            info.setPubRemark(cursor.getString(cursor.getColumnIndex(AppBaseInfo.PUB_REMARK)));
            info.setHardwareVer(cursor.getString(cursor.getColumnIndex(AppBaseInfo.HARDWARE_VER)));
            info.setPubType(cursor.getString(cursor.getColumnIndex(AppBaseInfo.PUB_TYPE)));
            info.setVerSortImg(cursor.getString(cursor.getColumnIndex(AppBaseInfo.VER_SORT_IMG)));
            info.setPubTime(cursor.getString(cursor.getColumnIndex(AppBaseInfo.PUB_TIME)));
            info.setApkFileSize(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APK_FILE_SIZE)));
            info.setAppPubStatus(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_PUB_STATUS)));
            info.setInstallDataTime(cursor.getString(cursor.getColumnIndex("installDataTime")));
            info.setInstallType(cursor.getInt(cursor.getColumnIndex("installType")));
            info.setAppPubId(cursor.getString(cursor.getColumnIndex("appPubId")));
            info.setAppStartActivity(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_START_ACTIVITY)));

            list.add(info);
        }
        cursor.close();
        return list;
    }

    @Override
    public AppBaseInfo getAppBaseInfoByPackageName(Context context, String packageName) {
        ContentResolver resolver = context.getContentResolver();
        //定义要访问的ContentProvider的
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + APP_BASE_INFO_BY_PACKAGENAME);

        Cursor cursor = null;
        try {
            //获取表中所有记录
            cursor = resolver.query(uri, null, null, new String[]{packageName}, null);
        } catch (Exception e) {
            LogUtil.e(logTag, logContent + e.getMessage());
            return null;
        }

        if (null == cursor) {
            return null;
        }
        AppBaseInfo info = null;

        while (cursor.moveToNext()) {
            info = new AppBaseInfo();
            info.setAppIcon(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_ICON)));
            info.setAppName(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_NAME)));
            info.setAppPackage(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_PACKAGE)));
            info.setAppId(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_ID)));
            info.setVerSortId(cursor.getString(cursor.getColumnIndex(AppBaseInfo.VER_SORT_ID)));
            info.setVerSortName(cursor.getString(cursor.getColumnIndex(AppBaseInfo.VER_SORT_NAME)));
            info.setVerTypeCode(cursor.getInt(cursor.getColumnIndex(AppBaseInfo.VER_TYPE_CODE)));
            info.setVerTypeName(cursor.getString(cursor.getColumnIndex(AppBaseInfo.VER_TYPE_NAME)));
            info.setAppPubStatus(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_PUB_STATUS)));
            info.setAddUpdate(cursor.getString(cursor.getColumnIndex(AppBaseInfo.ADD_UPDATE)));
            info.setVerCode(cursor.getString(cursor.getColumnIndex(AppBaseInfo.VER_CODE)));
            info.setDId(cursor.getString(cursor.getColumnIndex("dId")));
            info.setAppFilePath(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_FILE_PATH)));
            info.setUpdType(cursor.getString(cursor.getColumnIndex(AppBaseInfo.UPD_TYPE)));
            info.setAppUpdateState(cursor.getString(cursor.getColumnIndex(info.APP_UPDATE_STATE)));
            info.setIsAuthor(cursor.getString(cursor.getColumnIndex(AppBaseInfo.IS_AUTHOR)));
            info.setAppInstallMethod(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_INSTALL_METHOD)));
            info.setDeskName(cursor.getString(cursor.getColumnIndex(AppBaseInfo.DESK_NAME)));
            info.setAppStartActivity(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_START_ACTIVITY)));
            break;

        }

        cursor.close();
        return info;
    }

    /**
     * 保存最近使用app
     *
     * @param context
     * @param list
     * @param dId
     */
    @Override
    public void saveDesktopInfo(Context context, List<AppBaseInfo> list, String dId) {
        JSONArray ja = new JSONArray();
        for (AppBaseInfo info : list) {
            JSONObject jb = new JSONObject();
            try {
                jb.put(AppBaseInfo.APP_PACKAGE, info.getAppPackage());
                jb.put(AppBaseInfo.APP_ICON, info.getAppIcon());
                jb.put(AppBaseInfo.APP_ID, info.getAppId());
                jb.put(AppBaseInfo.APP_NAME, info.getAppName());
                jb.put(AppBaseInfo.APP_FILE_PATH, info.getAppFilePath());
                jb.put("dId", dId);
                jb.put(AppBaseInfo.IS_AUTHOR, info.getIsAuthor());
                jb.put(AppBaseInfo.UPD_TYPE, info.getUpdType());
                jb.put(AppBaseInfo.VER_CODE, info.getVerCode());
                jb.put(AppBaseInfo.VER_TYPE_CODE, info.getVerTypeCode());
                jb.put(AppBaseInfo.APP_INSTALL_METHOD, info.getAppInstallMethod());
                jb.put(AppBaseInfo.APP_START_ACTIVITY, info.getAppStartActivity());
                ja.put(jb);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        ContentResolver resolver = context.getContentResolver();
        //定义要访问的ContentProvider的
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + TABLE_MARKET_DESKTOP);
        ContentValues values = new ContentValues();
        values.put(intentId, ja.toString());
        resolver.insert(uri, values);
    }

    @Override
    public void clearTrafficStatsInfo(Context context) {
        ContentResolver resolver = context.getContentResolver();
        //定义要访问的ContentProvider的
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + TABLE_APP_TRAFFICSTATS);
        int result = resolver.delete(uri, null, null);

    }

    @Override
    public void saveTrafficStats(Context context, TrafficStatsInfo trafficStatsInfo) {
        ContentResolver resolver = context.getContentResolver();
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + TABLE_APP_TRAFFICSTATS);
        ContentValues contentValues = DataConversionUtil.BeanToContentValues(trafficStatsInfo);
        resolver.insert(uri, contentValues);
    }

    @Override
    public List<TrafficStatsInfo> getTrafficStatsInfos(Context context) {
        ContentResolver contentResolver = context.getContentResolver();
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + TABLE_APP_TRAFFICSTATS);
        Cursor cursor = null;

        try {
            //获取表中所有记录
            cursor = contentResolver.query(uri, null, null, new String[]{TABLE_APP_TRAFFICSTATS_ALL}, null);
        } catch (Exception e) {
            LogUtil.e(logTag, logContent + e.getMessage());
            return null;
        }
        if (null == cursor) {
            return null;
        }

        List<TrafficStatsInfo> list = DataConvert.cursor2VOList(cursor, TrafficStatsInfo.class);

        return list;
    }

    @Override
    public List<TrafficStatsInfo> getMonthTrafficMonitorInfos(Context context, String packageName) {

        ContentResolver contentResolver = context.getContentResolver();
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + TABLE_APP_TRAFFICSTATS);
        Cursor cursor = null;

        try {
            //获取表中所有记录
            cursor = contentResolver.query(uri, null, null, new String[]{TABLE_APP_TRAFFICSTATS_DAY, packageName}, null);
        } catch (Exception e) {
            LogUtil.e(logTag, logContent + e.getMessage());
            return null;
        }
        if (null == cursor) {
            return null;
        }

        List<TrafficStatsInfo> list = DataConvert.cursor2VOList(cursor, TrafficStatsInfo.class);

        return list;
    }


    @Override
    public List<TrafficStatsInfo> getDayTrafficMonitorInfos(Context context, String packageName) {

        ContentResolver contentResolver = context.getContentResolver();
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + TABLE_APP_TRAFFICSTATS);
        Cursor cursor = null;

        try {
            //获取表中所有记录
            cursor = contentResolver.query(uri, null, null, new String[]{TABLE_APP_TRAFFICSTATS_MONTH, packageName}, null);
        } catch (Exception e) {
            LogUtil.e(logTag, logContent + e.getMessage());
            return null;
        }
        if (null == cursor) {
            return null;
        }

        List<TrafficStatsInfo> list = DataConvert.cursor2VOList(cursor, TrafficStatsInfo.class);

        return list;
    }

    @Override
    public TaskUpInfo getTaskisUp(Context context, String workNo) {

        ContentResolver contentResolver = context.getContentResolver();
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + TABLE_APP_TASK_UP_INFO);
        Cursor cursor = null;

        try {
            //获取表中所有记录
            cursor = contentResolver.query(uri, null, null, new String[]{workNo}, null);
        } catch (Exception e) {
            LogUtil.e(logTag, logContent + e.getMessage());
            return null;
        }
        if (null == cursor) {
            return null;
        }
        TaskUpInfo info = null;
        while (cursor.moveToNext()) {
            if (info == null) {
                info = new TaskUpInfo();
            }
            info.setWorkNo(cursor.getString(cursor.getColumnIndex("workNo")));
            info.setWorkType(cursor.getString(cursor.getColumnIndex("workType")));
            info.setWorkNoUpTime(cursor.getLong(cursor.getColumnIndex("workNoUpTime")));
            info.setUpdate(cursor.getString(cursor.getColumnIndex("isUpdate")));
        }
        cursor.close();
        return info;
    }

    @Override
    public void saveTaskUpInfo(Context context, TaskUpInfo taskUpInfo) {

        ContentResolver resolver = context.getContentResolver();
        //定义要访问的ContentProvider的
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + TABLE_APP_TASK_UP_INFO);
        //通过反射  将实体类转成ContentValues
        ContentValues values = DataConversionUtil.BeanToContentValues(taskUpInfo);

        if (null == values) {
        } else {
            resolver.insert(uri, values);
        }

    }

    @Override
    public boolean deleteTaskUpInfo(Context context) {
        ContentResolver resolver = context.getContentResolver();
        //定义要访问的ContentProvider的
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + TABLE_APP_TASK_UP_INFO);
        int result = resolver.delete(uri, null, null);
        if (result == 1) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public void saveTaskConstantInfo(Context context, String taskConstantInfo) {
        ContentResolver resolver = context.getContentResolver();
        //定义要访问的ContentProvider的
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + TABLE_TASK_CONSTANT_INFO);
        ContentValues values = new ContentValues();
        values.put(intentId, taskConstantInfo);
        resolver.insert(uri, values);
    }

    @Override
    public void deleteTaskConstantInfo(Context mContext) {
        ContentResolver resolver = mContext.getContentResolver();
        //定义要访问的ContentProvider的
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + TABLE_TASK_CONSTANT_INFO);
        resolver.delete(uri, null, null);
    }

    @Override
    public ArrayList<DataBean> getTaskConstantInfo(Context context) {

        ContentResolver contentResolver = context.getContentResolver();
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + TABLE_TASK_CONSTANT_INFO);
        Cursor cursor = null;

        try {
            //获取表中所有记录
            cursor = contentResolver.query(uri, null, null, null, null);
        } catch (Exception e) {
            LogUtil.e(logTag, logContent + e.getMessage());
            return null;
        }
        if (null == cursor) {
            return null;
        }
        ArrayList<DataBean> dataBeanList = new ArrayList<>();
        DataBean info = null;
        while (cursor.moveToNext()) {
            info = new DataBean();
            info.setAppPackage(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_PACKAGE)));
            info.setMesChildTypeCode(cursor.getString(cursor.getColumnIndex("mesChildTypeCode")));
            info.setMesChildTypeName(cursor.getString(cursor.getColumnIndex("mesChildTypeName")));
            info.setAppInstallMethod(cursor.getString(cursor.getColumnIndex(AppBaseInfo.APP_INSTALL_METHOD)));
            dataBeanList.add(info);
        }
        cursor.close();
        return dataBeanList;
    }

    @Override
    public void saveBehaviorTrajectoryInfoContext(Context context, BehaviorTrajectoryInfo behaviorTrajectoryInfo) {
        ContentResolver resolver = context.getContentResolver();
        //定义要访问的ContentProvider的
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + BEHAVIOR_TRAJECTORY_INFO);
        //通过反射  将实体类转成ContentValues
        ContentValues values = DataConversionUtil.BeanToContentValues(behaviorTrajectoryInfo);

        if (null == values) {
        } else {
            resolver.insert(uri, values);
        }
    }

    @Override
    public void deleteBehaviorTrajectoryInfo(Context mContext, String businessIdentification, String sonBusinessIdentification) {
        ContentResolver resolver = mContext.getContentResolver();
        //定义要访问的ContentProvider的
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + BEHAVIOR_TRAJECTORY_INFO);
        resolver.delete(uri, null, new String[]{businessIdentification, sonBusinessIdentification});
    }

    @Override
    public boolean updateBehaviorTrajectoryInfo(Context mContext, String id) {
        ContentResolver resolver = mContext.getContentResolver();
        //定义要访问的ContentProvider的
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + BEHAVIOR_TRAJECTORY_INFO);
        ContentValues values = new ContentValues();
        values.put(intentId, "test");
        int result = resolver.update(uri, values, null, new String[]{id});
        if (result == 1) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public ArrayList<BehaviorTrajectoryInfo> getBehaviorTrajectoryInfo(Context context, String businessIdentification, String sonBusinessIdentification) {

        ContentResolver contentResolver = context.getContentResolver();
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + BEHAVIOR_TRAJECTORY_INFO);
        Cursor cursor = null;

        try {
            //获取表中所有记录
            cursor = contentResolver.query(uri, null, null, new String[]{businessIdentification, sonBusinessIdentification}, null);
        } catch (Exception e) {
            LogUtil.e(logTag, logContent + e.getMessage());
            return null;
        }
        if (null == cursor) {
            return null;
        }
        ArrayList<BehaviorTrajectoryInfo> behaviorTrajectoryInfoList = new ArrayList<>();
        BehaviorTrajectoryInfo info = null;
        while (cursor.moveToNext()) {
            info = new BehaviorTrajectoryInfo();
            info.setId(cursor.getLong(cursor.getColumnIndex("id")));
            info.setBusinessIdentification(cursor.getString(cursor.getColumnIndex("businessIdentification")));
            info.setSonBusinessIdentification(cursor.getString(cursor.getColumnIndex("sonBusinessIdentification")));
            info.setContent(cursor.getString(cursor.getColumnIndex("content")));
            info.setState(cursor.getString(cursor.getColumnIndex("state")));
            info.setInsertionTime(cursor.getString(cursor.getColumnIndex("insertionTime")));
            behaviorTrajectoryInfoList.add(info);
        }
        cursor.close();
        return behaviorTrajectoryInfoList;
    }

    @Override
    public void saveMsgOffline(Context context, MsgOfflineInfo info) {

        ContentResolver resolver = context.getContentResolver();
        //定义要访问的ContentProvider的
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + TABLE_APP_MSG_OFFLINE_INFO);
        //通过反射  将实体类转成ContentValues
        ContentValues values = DataConversionUtil.BeanToContentValues(info);
        if (null != values) {
            resolver.insert(uri, values);
        }
    }

    @Override
    public ArrayList<MsgOfflineInfo> getMsgOffline(Context context, String topic, String time) {
        ContentResolver contentResolver = context.getContentResolver();
        Uri uri = Uri.parse(CONTENT_PROVIDER_CONNECT + TABLE_APP_MSG_OFFLINE_INFO);
        Cursor cursor = null;

        try {
            //获取表中所有记录
            cursor = contentResolver.query(uri, null, null, new String[]{topic, time}, null);
        } catch (Exception e) {
            LogUtil.e(logTag, logContent + e.getMessage());
            return null;
        }
        if (null == cursor) {
            return null;
        }
        ArrayList<MsgOfflineInfo> msgOfflineInfos = new ArrayList<>();
        MsgOfflineInfo info = null;
        while (cursor.moveToNext()) {
            info = new MsgOfflineInfo();
            info.setTOPIC(cursor.getString(cursor.getColumnIndex("TOPIC")));
            info.setMSG(cursor.getString(cursor.getColumnIndex("MSG")));
            info.setTIME_ACCEPT(cursor.getString(cursor.getColumnIndex("TIME_ACCEPT")));
            msgOfflineInfos.add(info);
        }
        cursor.close();
        return msgOfflineInfos;
    }

}
